// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-10-16 09:35:57
 * @LastEditors: qiulin ql1746365080@gmail.com
 * @LastEditTime: 2024-12-12 15:14:38
 * @FilePath: \SGFEM\Import\BDFImport\BulkData\Element\CELAS1Parser.cpp
 */

#include "CELAS1Parser.h"

#include <algorithm>
#include <cstdint>
#include <iostream>

#include "Utility/Logging/SGLogger.h"

#include "DataStructure/Input/Element/CELAS1Data.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFParserBase.h"

BULKDATA_ENTRY_PARSER_REG (CELAS1);

using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure;
/*
// file://./../../Doc/MarkDown/BulkData/CELAS1/CELAS1.md>
*/
// 以下需要修改
enum CELAS1key : std::uint8_t
{
    CELAS1KEY_EID = 2,
    CELAS1KEY_PID = 3,
    CELAS1KEY_G1  = 4,
    CELAS1KEY_C1  = 5,
    CELAS1KEY_G2  = 6,
    CELAS1KEY_C2  = 7,
};
SG::DataStructure::Common::Status BDF::BULKDATA::ParseCELAS1 (const std::shared_ptr<SG::DBManager::DBServiceFactory>& dbServiceFactory,
                                                              std::vector<std::string>&                               dividedEntryInfo)
{
    SG::DataStructure::FEM::CELAS1Data tempCELAS1;

    // TODO(bug 001) m_dominId的正确填写
    tempCELAS1.m_domainId = 1;

    int curIDKey = 1;  // 当前字符串是第几项

    for (auto curStrKey : dividedEntryInfo)
    {
        bool const isEmpty = is_all_space (curStrKey);
        if (isEmpty)
        {
            curIDKey++;
            continue;
        }

        switch (curIDKey)
        {
        case CELAS1KEY_EID:
            tempCELAS1.m_id  = convertToI64 (curStrKey);
            tempCELAS1.m_pId = tempCELAS1.m_id;  // Default = EID
            break;
        case CELAS1KEY_PID:
            tempCELAS1.m_pId = convertToI64 (curStrKey);
            break;
        case CELAS1KEY_G1:
            tempCELAS1.m_g[0] = convertToI64 (curStrKey);
            break;
        case CELAS1KEY_C1:
            tempCELAS1.m_c1 = convertToI64 (curStrKey);
            break;
        case CELAS1KEY_G2:
            tempCELAS1.m_g[1] = convertToI64 (curStrKey);
            break;
        case CELAS1KEY_C2:
            tempCELAS1.m_c2 = convertToI64 (curStrKey);
            break;
        default:
            break;
        }
        curIDKey++;
    }

    return dbServiceFactory->get<IElementService> ()->Add (tempCELAS1);
}
